<%@page pageEncoding="UTF-8"%>
<%@include file="/common/common.jsp"%>
<%@include file="/common/skins/skin0/component.jsp" %>
<h:css href="/css/style1/style-custom.css"/>
<html>
<!-- 
  - Author(s): pengweiling
  - Date: 2012-07-16 14:34:05
  - Description:
-->
<head>
<title>入账</title>
</head>
<body>

<form name="dataform" action="com.hms.OrderMgr.Checkout.flow" checkType="blur" target="_self" method="post" onsubmit="return checkAccount(this);">
<input type="hidden" name="_eosFlowAction" value="checkout">

<table align="center" border="0" width="100%" class="form_table">
            <tr>
              <td class="form_label" style="width:20%">
                已结算金额
              </td>                          
              <td colspan="1" style="width:80%"> 
                <h:text property="creditAmt" readonly="true" style="width:200px;"/>
              </td>
             </tr>
            <tr>
              <td class="form_label" style="width:20%">
                已消费金额
              </td>                          
              <td colspan="1" style="width:80%"> 
                <h:text property="debitAmt" readonly="true" style="width:200px;"/>
              </td>
             </tr>
            <tr>
              <td class="form_label" style="width:20%">
               结算项目
              </td>                          
              <td colspan="1" style="width:80%"> 
                <w:lookup style="width:200px;" 
                          lookupUrl="com.hms.commonPick.WeItemSelect.flow"
                          allowInput="false"
                          dialogTitle="选择入账科目"
                          property="bill/citemcode"
                          onReturnFunc="handleItem"/>
                <h:hidden name="bill/igresid" property="gresId"/>
                <h:hidden property="bill/iitemid"/>
                <h:hidden name="checkout" value="N"/>
                
              </td>
             </tr>
            <tr>
              <td class="form_label" style="width:20%">
                项目名称
              </td>
              <td colspan="1" style="width:80%">
                <h:text  style="width:200px;" property="bill/citemdesc" readonly="true" />                                               
              </td>
             </tr>                
            <tr>
              <td class="form_label" style="width:20%">
                结算金额
              </td>
              <td colspan="1" style="width:80%">
                <l:equal property="isAll" targetValue="Y">
                <h:text  style="width:200px;" property="balance" readonly="true" name="bill/ncredit"/>    
                </l:equal>
                <l:notEqual property="isAll" targetValue="Y">
                <h:text  style="width:200px;" property="balance"  name="bill/ncredit"/>    
                </l:notEqual>
              </td>
             </tr>
             </tr>
             <tr>
              <td class="form_label" style="width:20%">
                备&nbsp;&nbsp;注
              </td>
              <td colspan="1" style="width:80%">
                <h:textarea  style="width:100%"  property="bill/cdescription"/>  
              </td>
             </tr>
                  
            <tr>
              <td class="form_label" align="center" colspan="2">
                <input type="submit" class="button" value="结&nbsp;账">
                <h:hidden property="bill/dbusinessdate"/>
                <input type="button" class="button" value="关&nbsp;闭" onclick="window.close();">
              </td>
             </tr>                                 
          </table>
</form>          

<script>

  function checkAccount(frm){     
     if (!trim($name("bill/iitemid").value)){
       alert("请选择入账科目!");
       return false;
     }
     
     //询问是否要退房
     if (!trim($name("bill/ncredit").value)){
       alert("请输入结账金额");
       return;
     }
     
     try{
        var x = Number(trim($name("bill/ncredit").value));
     }catch(e){
        alert("入账金额错误!");
        return false;
     }

                     
     if (<b:write property="creditAmt"/> - <b:write property="debitAmt"/> + Number(trim($name("bill/ncredit").value) <= 0.00001)){//如果账已经平了
        $name("checkout").value = confirm("是否需要退房？")?"Y":"N";
     }
     
     $name("bill/dbusinessdate").value = dateToString(window.dialogArguments.convertFunc(new Date()));
     
     if ($name("checkout").value == "Y"){//如果要退房，检查是否有物品租借、遗留、留言等
     
        <l:notEmpty property="info/hasLoan">
           <l:greaterThan property="info/hasLoan" targetValue="0" compareType="number">
              alert("当前房间还有物品租借，请先处理后再进行结账!");
              return false;
           </l:greaterThan>
        </l:notEmpty>
             
        <l:notEmpty property="info/hasMsg">
           <l:greaterThan property="info/hasMsg" targetValue="0" compareType="number">
              alert("当前房间还有客户留言，请先处理后再进行结账!");
              return false;
           </l:greaterThan>
        </l:notEmpty>
                     
        <l:notEmpty property="info/hasStorage">
           <l:greaterThan property="info/hasStorage" targetValue="0" compareType="number">
              alert("当前房间还有物品寄存，请先处理后再进行结账!");
              return false;
           </l:greaterThan>
        </l:notEmpty>
                             
        <l:notEmpty property="info/hasLost">
           <l:greaterThan property="info/hasLost" targetValue="0" compareType="number">
              alert("当前房间还有物品遗留，请先处理后再进行结账!");
              return false;
           </l:greaterThan>
        </l:notEmpty>
     }
     
     return true;
  }
  
  function handleItem(args){
     if (args){
       $name("bill/iitemid").value = args[0];
       args[0] = args[1];
       $name("bill/citemdesc").value = args[2];
     }
     return true;
  }
  
  <l:notEmpty property="bill/itransid">
     window.dialogArguments.loadFunc('<b:write property="bill/igresid"/>');
     window.close();
  </l:notEmpty>
  
</script>
</body>
</html>